import { defineStore } from 'pinia'
import api from '../utils/api'

export const useWardrobesStore = defineStore('wardrobes', {
  state: () => ({
    list: [],
    loading: false,
  }),
  actions: {
    async fetchList() {
      this.loading = true
      try {
        this.list = await api.get('/api/wardrobes')
      } finally {
        this.loading = false
      }
    },
    async createDisassembly(payload) {
      return api.post('/api/wardrobes/disassembly', payload)
    },
    async updateListing(id, payload) {
      return api.put(`/api/wardrobes/${id}/listing`, payload)
    },
    async markListed(id) {
      return api.put(`/api/wardrobes/${id}/listed`)
    },
    async upsertInstallation(id, payload) {
      return api.put(`/api/wardrobes/${id}/installation`, payload)
    },
    async settle(id, payload) {
      return api.post(`/api/wardrobes/${id}/settlement`, payload)
    },
    async archive(id) {
      return api.put(`/api/wardrobes/${id}/archive`)
    },
    async getDetail(id) {
      return api.get(`/api/wardrobes/${id}`)
    }
  }
})


